<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="couponStartTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['couponStartTime']" placeholder="请输入couponStartTime"></a-input>
        </a-form-item>
        <a-form-item label="couponEndTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['couponEndTime']" placeholder="请输入couponEndTime"></a-input>
        </a-form-item>
        <a-form-item label="infoDxjh" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['infoDxjh']" placeholder="请输入infoDxjh"></a-input>
        </a-form-item>
        <a-form-item label="tkTotalSales" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tkTotalSales']" placeholder="请输入tkTotalSales"></a-input>
        </a-form-item>
        <a-form-item label="tkTotalCommi" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tkTotalCommi']" placeholder="请输入tkTotalCommi"></a-input>
        </a-form-item>
        <a-form-item label="couponId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['couponId']" placeholder="请输入couponId"></a-input>
        </a-form-item>
        <a-form-item label="numIid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['numIid']" placeholder="请输入numIid" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="title" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['title']" placeholder="请输入title"></a-input>
        </a-form-item>
        <a-form-item label="pictUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['pictUrl']" rows="4" placeholder="请输入pictUrl"/>
        </a-form-item>
        <a-form-item label="smallImages" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['smallImages']" rows="4" placeholder="请输入smallImages"/>
        </a-form-item>
        <a-form-item label="reservePrice" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['reservePrice']" placeholder="请输入reservePrice"></a-input>
        </a-form-item>
        <a-form-item label="zkFinalPrice" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zkFinalPrice']" placeholder="请输入zkFinalPrice"></a-input>
        </a-form-item>
        <a-form-item label="userType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['userType']" placeholder="请输入userType" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="provcity" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['provcity']" placeholder="请输入provcity"></a-input>
        </a-form-item>
        <a-form-item label="includeMkt" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['includeMkt']" placeholder="请输入includeMkt"></a-input>
        </a-form-item>
        <a-form-item label="includeDxjh" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['includeDxjh']" placeholder="请输入includeDxjh"></a-input>
        </a-form-item>
        <a-form-item label="commissionRate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['commissionRate']" placeholder="请输入commissionRate"></a-input>
        </a-form-item>
        <a-form-item label="volume" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['volume']" placeholder="请输入volume" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="sellerId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['sellerId']" placeholder="请输入sellerId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponTotalCount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponTotalCount']" placeholder="请输入couponTotalCount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponRemainCount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['couponRemainCount']" placeholder="请输入couponRemainCount" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponInfo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['couponInfo']" placeholder="请输入couponInfo"></a-input>
        </a-form-item>
        <a-form-item label="commissionType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['commissionType']" placeholder="请输入commissionType"></a-input>
        </a-form-item>
        <a-form-item label="shopTitle" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shopTitle']" placeholder="请输入shopTitle"></a-input>
        </a-form-item>
        <a-form-item label="shopDsr" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['shopDsr']" placeholder="请输入shopDsr" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="couponShareUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['couponShareUrl']" rows="4" placeholder="请输入couponShareUrl"/>
        </a-form-item>
        <a-form-item label="url" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['url']" rows="4" placeholder="请输入url"/>
        </a-form-item>
        <a-form-item label="levelOneCategoryName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['levelOneCategoryName']" placeholder="请输入levelOneCategoryName"></a-input>
        </a-form-item>
        <a-form-item label="levelOneCategoryId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['levelOneCategoryId']" placeholder="请输入levelOneCategoryId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="categoryName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['categoryName']" placeholder="请输入categoryName"></a-input>
        </a-form-item>
        <a-form-item label="categoryId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['categoryId']" placeholder="请输入categoryId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="shortTitle" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shortTitle']" placeholder="请输入shortTitle"></a-input>
        </a-form-item>
        <a-form-item label="whiteImage" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['whiteImage']" rows="4" placeholder="请输入whiteImage"/>
        </a-form-item>
        <a-form-item label="oetime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oetime']" placeholder="请输入oetime"></a-input>
        </a-form-item>
        <a-form-item label="ostime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ostime']" placeholder="请输入ostime"></a-input>
        </a-form-item>
        <a-form-item label="jddNum" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['jddNum']" placeholder="请输入jddNum" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="jddPrice" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jddPrice']" placeholder="请输入jddPrice"></a-input>
        </a-form-item>
        <a-form-item label="tokenTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tokenTime']" placeholder="请输入tokenTime"></a-input>
        </a-form-item>
        <a-form-item label="token" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['token']" placeholder="请输入token"></a-input>
        </a-form-item>
        <a-form-item label="couponAmount" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['couponAmount']" placeholder="请输入couponAmount"></a-input>
        </a-form-item>
        <a-form-item label="sort" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sort']" placeholder="请输入sort"></a-input>
        </a-form-item>
        <a-form-item label="type" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['type']" placeholder="请输入type"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'


  export default {
    name: "TbMnMaterialOptionalModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/mall/tbMnMaterialOptional/add",
          edit: "/mall/tbMnMaterialOptional/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'couponStartTime','couponEndTime','infoDxjh','tkTotalSales','tkTotalCommi','couponId','numIid','title','pictUrl','smallImages','reservePrice','zkFinalPrice','userType','provcity','includeMkt','includeDxjh','commissionRate','volume','sellerId','couponTotalCount','couponRemainCount','couponInfo','commissionType','shopTitle','shopDsr','couponShareUrl','url','levelOneCategoryName','levelOneCategoryId','categoryName','categoryId','shortTitle','whiteImage','oetime','ostime','jddNum','jddPrice','tokenTime','token','couponAmount','sort','type'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'couponStartTime','couponEndTime','infoDxjh','tkTotalSales','tkTotalCommi','couponId','numIid','title','pictUrl','smallImages','reservePrice','zkFinalPrice','userType','provcity','includeMkt','includeDxjh','commissionRate','volume','sellerId','couponTotalCount','couponRemainCount','couponInfo','commissionType','shopTitle','shopDsr','couponShareUrl','url','levelOneCategoryName','levelOneCategoryId','categoryName','categoryId','shortTitle','whiteImage','oetime','ostime','jddNum','jddPrice','tokenTime','token','couponAmount','sort','type'))
      },

      
    }
  }
</script>